package com.basic.util;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * @author xl-9527
 * @since 2024/12/16
 **/
public class JSON {

    private static final ObjectMapper objectMapper = new ObjectMapper();

    public static <T> T parseObject(String json, Class<T> clazz) {
        return parseObject(json.getBytes(StandardCharsets.UTF_8), clazz);
    }

    public static <T> T parseObject(byte[] json, Class<T> clazz) {
        try {
            return objectMapper.readValue(json, clazz);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
